package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.OutZhiJieDTO;
import com.wms.entity.*;
import com.wms.service.BStockOutRecordService;
import com.wms.service.OutService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "出货管理")
public class OutController {
    @Autowired
    OutService outService;
    @Autowired
    BStockOutRecordService stockOutRecordService;

    @PostMapping("/tuihuo")
    @ApiOperation("退货任务单查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "任务编号",dataType = "int"),
            @ApiImplicitParam(name = "status",value = "完成状态",dataType = "int"),
            @ApiImplicitParam(name = "startTime",value = "起始日期",dataType = "String"),
            @ApiImplicitParam(name = "endTime",value = "结束日期",dataType = "String"),
    })
    public PageBean chaTuiHuo(Integer id, Integer status, String startTime,
                              String endTime,Integer pageNum, Integer pageSize){

        return outService.chaTuiHuo(id,status,startTime,endTime,pageNum,pageSize);
    }

    @ApiOperation("商品、产品、直接 出库查询")
    @PostMapping("/ChanShangZhi")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "startTime",value = "起始日期",dataType = "String"),
//            @ApiImplicitParam(name = "endTime",value = "结束日期",dataType = "String"),
//            @ApiImplicitParam(name = "type",value = "2 产品出库3 商品出库4 直接出库",dataType = "int",required = true),
//            @ApiImplicitParam(name = "id",value = "任务编号",dataType = "Integer"),
//            @ApiImplicitParam(name = "status",value = "完成状态 1未完成2部分完成3已完成",dataType = "Integer"),
//            @ApiImplicitParam(name = "chukuType",value = "出库类型",dataType = "Integer"),
//            @ApiImplicitParam(name = "category",value = "出库物品品类",dataType = "String"),
//            @ApiImplicitParam(name = "warmarea",value = "温区",dataType = "String"),
//            @ApiImplicitParam(name = "tiem",value = "出库物品",dataType = "String"),
//            @ApiImplicitParam(name = "reason",value = "出库原因",dataType = "String"),
//            @ApiImplicitParam(name = "page",value = "页码",dataType = "Integer",example = "1"),
//            @ApiImplicitParam(name = "pageSize",value = "单页显示条数",dataType = "Integer",example = "5")
//    })

    public ResultBean ChanShangZhi(@RequestBody  OutZhiJieDTO outZhiJieDTO){
            PageBean pageBean=outService.ChanShangZhi(outZhiJieDTO);
        return R.success("查询结果",pageBean) ;
    }

    @ApiOperation("直接出库 产品、商品 任务添加")
    @PostMapping("/addZhiJie")
    public ResultBean addZhiJie(@ApiParam(value = "出库完整信息", required = true)
                                    @RequestBody OutSanheyi wrapper ){
        int n=outService.createStockOut(wrapper.getTask(),wrapper.getDirect(),wrapper.getDetails());
        return R.success("添加任务",n);
    }

    @PostMapping("/Allmingxi")
    @ApiOperation("查询所有出库明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "单页条数",required = true,dataType = "int")
    })
    public PageBean Allmingxi(int page,int pageSize){
        return outService.Allmingxi(page,pageSize);
    }



    @PostMapping("/out/addPurchase")
    @ApiOperation("退货任务添加")
    public ResultBean save(@RequestBody OutStorePurchase outStorePurchase){
        outService.save(outStorePurchase);
        return null;
    }






    // 增加出库任务 选货品
    @GetMapping("/outMaterial")
    @ApiOperation("选择出库物品")
    public ResultBean outMaterial(int page,int pageSize){
        PageBean pageBean=outService.outMaterial(page,pageSize);
        return R.success("选择出库物品",pageBean);
    }

    //直接出库任务明细
    @GetMapping("/outZJdetail")
    @ApiOperation("根据任务id查直接出库明细")
    public ResultBean outZJdeatil(String id,int page,int pageSize){
        PageBean pageBean=outService.outZJdeatil(id,page,pageSize);
        return R.success("直接出库明细",pageBean);
    }


    @GetMapping("/outJiLu")
    @ApiOperation("出库记录")
    public ResultBean outjilu(Integer productId){
        List<Map> list=outService.outjilu(productId);
        return R.success("出库记录",list);
    }




    /**
     * 查询产品出库记录
     */
    @PostMapping ("/addoutJiLu")
    @ApiOperation("添加出库记录")
    public ResultBean Queryoutjilu( @RequestBody BStockOutRecord bStockOutRecord ) {
        // 调用业务层获取出库记录
        stockOutRecordService.addStockOutRecord(bStockOutRecord);
        return R.success("出库记录添加");
    }
}
